<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>工程概况</title>
    <meta name="renderer" content="webkit" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0"
    />
    <link
      rel="stylesheet"
      href="../../layuiadmin/layui/css/layui.css"
      media="all"
    />
    <link
      rel="stylesheet"
      href="../../layuiadmin/style/admin.css"
      media="all"
    />
    <link
      rel="stylesheet"
      href="../../layuiadmin/style/style.css"
      media="all"
    />
  </head>
  <body>
    <div class="layui-fluid">
      <img
        src="../../layuiadmin/images/backPage.png"
        class="backPreviousPage"
      />
      <button class="layui-btn layuiadmin-btn-useradmin downLoadWord">
        下载
      </button>
      <button class="layui-btn layuiadmin-btn-useradmin deleteTechnical">
        删除
      </button>
      <div class="time_axis">
        <div class="time_box">
          <div class="time_box_list">
            <ul class="time_horizontal"></ul>
          </div>
        </div>
      </div>
      <iframe id="pdf"></iframe>
      <div class="seePdfBox"></div>
    </div>
    <script src="../../layuiadmin/modules/const_config.js"></script>
    <script src="../../layuiadmin/modules/jTools.js"></script>
    <script src="../../layuiadmin/layui/layui.js"></script>
    <script>
      layui
        .config({
          base: "../../layuiadmin/", //静态资源所在路径
          version: "20210514",
        })
        .extend({
          index: "lib/index", //主入口模块
        })
        .use(["index", "table"], function () {
          var table = layui.table,
            $ = layui.$,
            form = layui.form,
            uuid = layui.data("uuid").key,
            reviewType = layui.data("reviewType").key,
            type = layui.data("technicalType").key;
          var fileid = "";
          permissionList();
          function permissionList() {
            $.ajax({
              type: "post",
              async: true, //异步执行
              url: base_url + "/Technical/permissionList",
              headers: {
                Accept: "application/json; charset=utf-8",
                Authorization: layui.sessionData("userToken").key,
              },
              contentType: "application/json",
              data: JSON.stringify({
                uuid,
                type,
                reviewType,
              }),
              success: function (data) {
                if (data.type == "success") {
                  var data = data.data.reverse();
                  var html = "";
                  for (var i = 0; i < data.length; i++) {
                    if (i == data.length - 1) {
                      fileid = data[i].fileId;
                      html += `
                    <li class="time_horizontal_part" data-id="${data[i].pdfName}" data-fileid="${data[i].fileId}" data-name="${data[i].fileName}" >
                        <b class="active"></b>
                        ${data[i].createTime}<br/>
                    </li>`;
                      $("#pdf").attr(
                        "src",
                        "../../layuiadmin/web/viewer.html?file=" +
                          data[i].pdfName
                      );
                    } else {
                      html += `
                    <li class="time_horizontal_part" data-id="${data[i].pdfName}" data-fileid="${data[i].fileId}" data-name="${data[i].fileName}">
                        <b></b>
                        ${data[i].createTime}<br/>
                    </li>`;
                    }
                  }
                }
                $(".time_horizontal").html(html);
                $(".time_horizontal_part").on("click", function () {
                  var uuid = $(this).attr("data-id");
                  fileid = $(this).attr("data-fileid");
                  $(this).children("b").addClass("active");
                  $(this).siblings("li").children("b").removeClass("active");
                  $("#pdf").attr(
                    "src",
                    "../../layuiadmin/web/viewer.html?file=" + uuid
                  );
                });
                $(".downLoadWord").on("click", function () {
                  window.location.href = $(".active")
                    .parent()
                    .attr("data-name");
                });
                $(".time_horizontal").scrollLeft(
                  $(".time_horizontal")[0].scrollWidth
                );
              },
            });
          }

          $(".deleteTechnical").on("click", function () {
            $.ajax({
              type: "post",
              async: true, //异步执行
              url: base_url + "/Technical/technicaldelect",
              headers: {
                Accept: "application/json; charset=utf-8",
                Authorization: layui.sessionData("userToken").key,
              },
              contentType: "application/json",
              data: JSON.stringify({ fileid: fileid }),
              success: function (data) {
                if ((data.type = "success")) {
                  var dom = document.querySelectorAll("ul>li");
                  var url = $(".active").parent().attr("data-id");
                  if (dom.length == 1) {
                    $("#pdf").attr("src", " ");
                  } else {
                    permissionList();
                  }
                  layer.confirm("确认删除吗?", function (index) {
                    $(".active").parent().remove();
                    layer.msg(data.message, { icon: 6 });
                  });
                } else {
                  layer.msg(data.message, { icon: 5 });
                }
              },
            });
          });
          $(".backPreviousPage").on("click", function () {
            $(this).attr("lay-href", "./pages/technicalReview.html");
          });
        });
    </script>
  </body>
</html>
